package com.ui_componet.looppic.factory;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.widget.ImageView;

import com.bumptech.glide.DrawableTypeRequest;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.ui_componet.R;

import java.io.File;

/**
 * Created by tanghongbin on 2017/3/9.
 */

public class ImageViewFactory extends AbsViewFactory {


    @Override
    public ImageView getImageView(Context context, String uri) {
        RequestManager manager = Glide.with(context);
        DrawableTypeRequest drawablerequest = null;
        ImageView imageView = (ImageView) LayoutInflater.from(context).
                inflate(R.layout.image_view_banner,null);
        if (!TextUtils.isEmpty(uri)) {
            if (!uri.contains("http")) {
                drawablerequest =  manager.load(new File(uri));
            } else {
                if (!(TextUtils.isEmpty(uri)) && uri.contains("@")) {
                    uri = uri.substring(0, uri.indexOf("@"));
                }
                drawablerequest =  manager.load(uri);
            }
            drawablerequest.into(imageView);
        }else {
            imageView.setImageResource(R.drawable.zhanweitu);
        }


        return imageView;
    }
}
